package com.java.test.system.feesettings;

import com.java.test.controller.BaseController;
import com.java.test.dto.PageResultDTO;
import com.java.test.dto.ResponseDTO;
import com.java.test.system.dto.LoginAccountInfo;
import com.java.test.system.feesettings.dto.FeeSettingsAddDTO;
import com.java.test.system.feesettings.dto.FeeSettingsDTO;
import com.java.test.system.feesettings.dto.FeeSettingsQueryDTO;
import com.java.test.system.feesettings.dto.FeeSettingsUpdateDTO;
import com.java.test.system.feesettings.vo.FeeSettingsVO;
import com.java.test.system.feesettings.vo.FeeTypeVO;
import com.java.test.system.feesettings.vo.MemberLVVO;
import com.java.test.timer.MessagePushTimer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Date;
import java.util.List;

/**
 * 手续费设置Controller
 *
 * @author lijie1
 * @date 2020/6/30 0030
 */
@Slf4j
@RestController
@RequestMapping("/systemConfig/feeSettings")
public class FeeSettingsController extends BaseController {

    FeeSettingsService feeSettingsService;
    @Autowired
    public void setFeeSettingsService(FeeSettingsService feeSettingsService) {
        this.feeSettingsService = feeSettingsService;
    }

    /**
     * 查询
     * @return
     */
    @RequestMapping(value = "/selectToList",method = RequestMethod.POST)
    public ResponseDTO<PageResultDTO<FeeSettingsVO>> selectByList(@RequestBody @Valid FeeSettingsQueryDTO queryDTO) {
        log.debug("----------手续费设置列表查询----------");
        return feeSettingsService.getSelectByList(queryDTO);
    }

    /**
     * 新增
     * @return
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public ResponseDTO<String> save(@RequestBody @Valid FeeSettingsAddDTO addDTO, HttpServletRequest request) {
        log.info("----------手续费设置添加----------");
        addDTO.setStatus(1);
        addDTO.setCreateTime(new Date());
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "系统管理-手续费设置-手续费设置添加");
        addDTO.setOperation(user.getLoginAccout());
        MessagePushTimer.QKFeeCLQ.offer("QKFeeCLQ");
        return feeSettingsService.save(addDTO);
    }

    /**
     * 通过id获取数据
     * @param dto
     * @return
     */
    @RequestMapping(value = "/selectById",method = RequestMethod.POST)
    public ResponseDTO<FeeSettingsVO> selectById(@RequestBody @Valid FeeSettingsDTO dto) {
        log.info("----------手续费设置查询----------");
        return feeSettingsService.selectById(dto.getId());
    }

    /**
     * 通过id修改数据
     * @param updateDTO
     * @return
     */
    @RequestMapping(value = "/updateById",method = RequestMethod.POST)
    public ResponseDTO<String> updateById(@RequestBody @Valid FeeSettingsUpdateDTO updateDTO, HttpServletRequest request) {
        log.info("----------手续费设置修改----------");
        updateDTO.setModifyTime(new Date());
        updateDTO.setStatus(1);
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "系统管理-手续费设置-手续费设置修改");
        MessagePushTimer.QKFeeCLQ.offer("QKFeeCLQ");
        return feeSettingsService.updateById(updateDTO);
    }

    /**
     * 通过id删除数据
     * @param dto
     * @return
     */
    @RequestMapping(value = "/deleteById",method = RequestMethod.POST)
    public ResponseDTO<String> deleteById(@RequestBody @Valid FeeSettingsDTO dto, HttpServletRequest request) {
        log.info("----------手续费设置删除----------");
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "系统管理-手续费设置-手续费设置删除");
        MessagePushTimer.QKFeeCLQ.offer("QKFeeCLQ");
        return feeSettingsService.deleteById(dto.getId());
    }

    /**
     * 查询手续费类型
     * @return
     */
    @RequestMapping(value = "/selectToListByFeeType",method = RequestMethod.POST)
    public ResponseDTO<List<FeeTypeVO>> selectToListByFeeType() {
        log.info("----------查询手续费类型----------");
        return feeSettingsService.selectToListByFeeType();
    }

    /**
     * 查询手续费类型
     * @return
     */
    @RequestMapping(value = "/selectToListByLV",method = RequestMethod.POST)
    public ResponseDTO<List<MemberLVVO>> selectToListByLV(@RequestBody @Valid FeeSettingsDTO dto) {
        log.info("----------查询手续费类型----------");
        return feeSettingsService.selectToListByLV(dto.getFeeType());
    }

}
